package com.example.fpe_vote.db2.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.fpe_vote.db2.entity.Ygzlw;
import com.example.fpe_vote.db2.mapper.YgzlwMapper;
import com.example.fpe_vote.db2.service.IYgzlwService;
import com.example.fpe_vote.db2.service.IZlemployeeService;
import com.example.fpe_vote.vo.request.RequestLoginCheckVo;
import com.example.fpe_vote.vo.response.ResponseUserInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2022-12-01
 */
@Service
@DS("slave_1")
public class YgzlwServiceImpl extends ServiceImpl<YgzlwMapper, Ygzlw> implements IYgzlwService {
    @Autowired
    IZlemployeeService zlemployeeService;

    @Override
    public ResponseUserInfoVo queryOne(RequestLoginCheckVo vo) {
        QueryWrapper<Ygzlw> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("Name",vo.getUserName());
        queryWrapper.eq("ghid",vo.getWorkerNo());
        //校验身份证是否正确
        String trueSFZ=zlemployeeService.querySFZByGhid(vo.getWorkerNo());
        if(Objects.equals(vo.getSfz(), trueSFZ)){
            List<Ygzlw> list=list(queryWrapper);
            if(list==null||list.size()==0){
                return null;
            }else {
                Ygzlw ygzlw=list.get(0);
                ResponseUserInfoVo userInfoVo=new ResponseUserInfoVo();
                BeanUtils.copyProperties(ygzlw,userInfoVo);
                userInfoVo.setSfz(trueSFZ);
                return userInfoVo;
            }
        }else
            return null;
    }

    @Override
    public Ygzlw queryByInfo(String userName, String ghid,String sfz) {
        QueryWrapper<Ygzlw> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("Name",userName);
        queryWrapper.eq("ghid",ghid);
        //校验身份证是否正确
        String trueSFZ=zlemployeeService.querySFZByGhid(ghid);
        if(Objects.equals(sfz, trueSFZ)){
            List<Ygzlw> list=list(queryWrapper);
            if(list==null||list.size()==0){
                return null;
            }
            return list.get(0);
        }else
            return null;
    }
}
